//
//  AboutManufacturerViewController.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "AboutManufacturerViewController.h"
#import "MyTableViewCell.h"

@interface AboutManufacturerViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIView *headerView;
@property (nonatomic,strong) UIView *footerView;
@property (nonatomic,strong) UIView *funcView;
@property (nonatomic,strong) UITextView *textView;

@property (nonatomic,strong) NSArray *dataArray;
@property (nonatomic,strong) NSDictionary *dataDictionary;

@end

//网络
@implementation AboutManufacturerViewController (NetWorking)

- (void)getData{
    [self showprogressHUD];
    NSDictionary *parameters = @{};
    [[AFAppDotNetAPIClient sharedClient] GET:@"aboutVenderController/aboutVender.action" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([responseObject[@"responseState"] integerValue] == 0) {
            self.dataDictionary = [responseObject[@"obj"] firstObject];
            self.textView.text = self.dataDictionary[@"aboutVenderInformation"];
            [self.view addSubview:self.funcView];
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}

@end

//UI
@implementation AboutManufacturerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    self.navigationItem.title = @"关于厂商";
    [self.view addSubview:self.tableView];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}

#pragma marl - Event

- (void)callEvent{
    [self callPhone:@"15641944668"];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MyTableViewCell class])];
    cell.dataDictionary = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

#pragma mark - set & get

- (UITableView *)tableView{
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.sectionFooterHeight = .01;
        _tableView.sectionHeaderHeight = .01;
        _tableView.tableFooterView = self.footerView;
        _tableView.tableHeaderView = self.headerView;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.scrollEnabled = NO;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([MyTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([MyTableViewCell class])];

    }
    return _tableView;
}

- (UIView *)funcView{
    if (!_funcView) {
        _funcView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 64 - 44, SCREEN_WIDTH, 44)];
        _funcView.backgroundColor = getColor(@"3b3b3b");
        
        UIButton *callBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200/WIDTH_5S_SCALE, 44)];
        callBtn.center = CGPointMake(SCREEN_WIDTH/2., _funcView.frame.size.height/2.);
        [callBtn setTitle:[NSString stringWithFormat:@"   联系我们 %@",self.dataDictionary[@"venderphone"]] forState:UIControlStateNormal];
        callBtn.titleLabel.font = DEF_FontSize_15;
        [callBtn setImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];

        [callBtn addTarget:self action:@selector(callEvent) forControlEvents:UIControlEventTouchUpInside];
        [_funcView addSubview:callBtn];
    }
    return _funcView;
}

- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.01)];
    }
    return _headerView;
}

- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-88)];
        _footerView.backgroundColor = [UIColor whiteColor];
        [_footerView.layer addSublayer:({
            CALayer *layer = [CALayer layer];
            layer.backgroundColor = getColor(@"f1f2f6").CGColor;
            layer.frame = CGRectMake(0, 0, SCREEN_WIDTH, 5);
            layer;
        })];
        
        _textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH-20, _footerView.frame.size.height-5)];
        _textView.editable = NO;
        _textView.showsVerticalScrollIndicator = NO;
        _textView.showsHorizontalScrollIndicator = NO;
        _textView.bounces = NO;
        _textView.text = @"";
        
        [_footerView addSubview:_textView];
    }
    return _footerView;
}

- (NSArray *)dataArray{
    if (!_dataArray) {
        _dataArray = @[@{@"img":@"text",@"title":@"信息说明",@"flag":@"0"}];
    }
    return _dataArray;
}

- (NSDictionary *)dataDictionary{
    if (!_dataDictionary) {
        _dataDictionary = @{};
    }
    return _dataDictionary;
}

@end
